<template>
	<view class="mx-30">
		<view class="my-12">
			<u-field v-model="form.oldPassword" label="原密码" :border-bottom="false" placeholder="请输入原密码" />
		</view>
		<view class="my-12">
			<u-field v-model="form.password" label="新密码" :border-bottom="false" placeholder="请输入新密码" />
		</view>
		<view class="my-12">
			<u-field v-model="passwordT" label="确认密码" :border-bottom="false" placeholder="请再次输入新密码" />
		</view>
		<view class="my-60">
			<u-button type="primary" @click="submit()">提交</u-button>
		</view>
	</view>
</template>

<script>
	import md5 from 'js-md5';
	export default {
		data() {
			return {
				form:{
					oldPassword: '',
					password: '',
				},
				passwordT: ''
			}
		},
		methods: {
			submit(){
				if(!this.form.oldPassword) return this.$u.toast('原密码不能为空');
				if(this.form.oldPassword == this.form.password) return this.$u.toast('新密码不能与原密码一致');
				if(this.form.password.length < 6 || this.passwordT.length < 6) return this.$u.toast('密码不能小于6位数');
				if(!this.form.password) return this.$u.toast('请输入新密码');
				if(!this.passwordT) return this.$u.toast('请输入确认密码');
				if(this.form.password != this.passwordT) return this.$u.toast('两次输入密码不一致');
				const oldPassword = md5(this.form.oldPassword);
				const password = md5(this.form.password);
				this.$u.api.updateDeliveryInfoPassword({
					oldPassword,
					password,
					id: uni.getStorageSync('riderUserInfo').id
				}).then(res=>{
					uni.showToast({
						title: '密码修改成功'
					})
					setTimeout(()=>{
						uni.reLaunch({
							url: '/pages/login/login'
						})
					},1200)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>